#// *************************************************************************
#// * COPYRIGHT 2004, EMULEX CORPORATION                                    *
#// * 3333 Susan Street, Costa Mesa, CA 92626                               *
#// *                                                                       *
#// * All rights reserved.  This computer program and related documentation *
#// * is protected by copyright  and distributed under licenses restricting *
#// * its use,  copying,  distribution  and decompilation.    This computer *
#// * program  and its  documentation  are CONFIDENTIAL  and a TRADE SECRET *
#// * of EMULEX CORPORATION.   The receipt or  possession of  this  program *
#// * or its documentation does not  convey rights to reproduce or disclose *
#// * its  contents,  or to  manufacture, use, or sell anything that it may *
#// * describe, in whole or in part,  without the specific  written consent *
#// * of  EMULEX CORPORATION.   Any reproduction  of  this program  without *
#// * the express  written  consent  of EMULEX  CORPORATION  is a violation *
#// * of the  copyright laws  and may  subject you to  criminal prosecution.*
#// *************************************************************************

#
# This script uninstalls HBAnyware or HBAnywareSSC for Linux
#
                                                                                                                        

opt="$1"

SSCUninstall=0

# Check if HBAnywareSSC uninstall option is passed in
if [ -n "$opt" ];then
    opt=`echo $opt | tr A-Z a-z`
    if [ "$opt" = "ssc" ];then
        SSCUninstall=1
    fi
fi

# Get environment data
OS=`uname -s`
Arch=`uname -m`
if [ "$Arch" = "i686" ];then
    Arch="i386"
fi
if [ "$Arch" = "x86_64" ];then
    Arch="i386"
    X86_64=1
else
    X86_64=0
fi
GCC_Ver=`gcc -v 2>&1 | grep version | awk '{ print $3 }' | awk -F. '{ print $1 }'`
OS_Type=`if [ -d /usr/src/redhat ];then echo "RH";else echo "SL";fi`
if [ "$OS_Type" = "RH" ];then
    if [ "$GCC_Ver" -eq 2 ];then
        OS_Ver="rhel-2.1"
    else
        OS_Ver="rhel-3.0"
    fi
else
    OS_Ver="sles-8.0"
fi

                                                                                                                          
# This is a Linux uninstall only, if we're not on Linux then stop
if [ "$OS" = "Linux" ];then
        Kernel_Ver=`uname -r 2>&1 | awk '{ print $1 }' | awk -F. '{ print $1$2 }'`
else
    echo "This uninstallation is for Linux only! Exiting..."
    exit
fi

# HBAnyware Uninstall
if [ $SSCUninstall -eq 0 ];then

    Cur_HBA=`rpm -qa | grep HBAnyware | grep -v SSC`
    if [ -n "$Cur_HBA" ];then
        echo "Uninstalling HBAnyware -- $Cur_HBA -- ..."
        rpm -e --nodeps "$Cur_HBA"
        echo ""
    fi
 
    # Uninstall dfc libs and utility
    rm -f /usr/sbin/lpfc/dfc
    rm -f /usr/lib/libdfc.so
    rm -f /usr/lib/libmpl.so
    rm -f /usr/lib/libdfc.a
    rm -f /usr/lib64/libdfc.so
    rm -f /usr/lib64/libdfc.a
    rm -f /usr/lib64/libmpl.so
    rm -f /usr/sbin/lpfc/lun_scan


    # Uninstall HBAAPI libs
    rm -f /usr/lib/libHBAAPI.so
    rm -f /usr/lib/libemulexhbaapi.so
    rm -f /usr/lib64/libHBAAPI.so
    rm -f /usr/lib64/libemulexhbaapi.so


    # Uninstall lputil utility
    rm -f /usr/sbin/lpfc/lputil

    # Uninstall JRE
    rm -rf /usr/sbin/hbanyware/jre

    rm -f /usr/sbin/hbanyware/READ*.txt
    rmdir --ignore-fail-on-non-empty /usr/sbin/hbanyware
    rmdir --ignore-fail-on-non-empty /usr/sbin/lpfc
    rm -f /usr/lib/lib_unix-rm/lib_rm_unix.so
    rm -f /usr/lib64/lib_unix-rm/lib_rm_unix.so

    echo "HBAnyware Uninstallation complete."
    echo ""



#  HBAnywareSSC Uninstallation
else   
    # Uninstall any previousely installed HBAnywareSSC
    Cur_HBA=`rpm -qa | grep HBAnywareSSC`
    if [ -n "$Cur_HBA" ];then
        echo "Uninstalling HBAnywareSSC -- $Cur_HBA -- ..."
        rpm -e "$Cur_HBA"
    fi

    echo "HBAnywareSSC Uninstallation complete."
    echo ""
fi


# Clean up
echo "Cleaning up..."
rm -rf ./*.XX
rm -rf ./jre_*
rm -rf utils
rm -rf hbaapi
rm -rf lpfcutil
echo ""

cd ..

